package com.way.controller;

import com.way.domain.dto.SysUserDto;
import com.way.domain.vo.SysUserVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Tag(name = "用户管理")
@RequestMapping("user")
@RestController
public class SysUserController {

    @Operation(summary = "查询所有用户")
    @GetMapping("/")
    public List<SysUserVo> findAll() {
        List<SysUserVo> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            SysUserVo user = new SysUserVo();
            user.setUsername("username-" + i);
            user.setPassword("password-" + i);
            user.setRemark("Remark-" + i);
            list.add(user);
        }
        return list;
    }

    @Operation(summary = "按ID查用户信息")
    @GetMapping("/{id}")
    public SysUserVo findById(@Parameter(description = "用户ID") @PathVariable("id") Integer id) {
        SysUserVo user = new SysUserVo();
        user.setUsername("username-" + id);
        user.setPassword("password-" + id);
        user.setRemark("Remark-" + id);
        return user;
    }

    @Operation(summary = "登录")
    @PostMapping("/")
    public SysUserVo login(@RequestBody SysUserDto dto) {
        SysUserVo user = new SysUserVo();
        BeanUtils.copyProperties(dto, user);
        user.setRemark("Remark-" + user.getUsername());
        return user;
    }

}
